﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using PromotionApp.Model;

namespace PromotionApp.DAL
{
    public class InternalUserDAL : BaseDAL
    {
         #region Private Variable

        private static InternalUserDAL _InternalUserDAL = null;

        #endregion

        #region Constructor

        private InternalUserDAL() : base()
        {

        }

        #endregion

        #region Public Method        

        public int CountByUserNameUpdate(int userId, string strUserName)
        {
            string strStoredProcedure = "MsInternalUserCountByUserNameUpdate";
            List<SqlParameter> list = new List<SqlParameter>();
            list.Add(new SqlParameter("UserId", userId));
            list.Add(new SqlParameter("UserName", strUserName));

            return Convert.ToInt32(this._SQLHelper.ExecuteScalar(strStoredProcedure, list, CommandType.StoredProcedure));
        }
    
        public int CountByUserNameInsert(string strUserName)
        {
            string strStoredProcedure = "MsInternalUserCountByUserNameInsert";
            List<SqlParameter> list = new List<SqlParameter>();
            list.Add(new SqlParameter("UserName", strUserName));

            return Convert.ToInt32(this._SQLHelper.ExecuteScalar(strStoredProcedure, list, CommandType.StoredProcedure));
        }

        public void Delete(int userId)
        {
            string strStoredProcedure = "MsInternalUserDelete";
            List<SqlParameter> list = new List<SqlParameter>();
            list.Add(new SqlParameter("UserId", userId));
            this._SQLHelper.ExecuteNonQuery(strStoredProcedure, list, CommandType.StoredProcedure);
        }

        public void Add(InternalUser user)
        {
            string strStoredProcedure = "MsInternalUserInsert";
            List<SqlParameter> list = new List<SqlParameter>();
            list.Add(new SqlParameter("UserName", user.UserName));
            list.Add(new SqlParameter("UserTypeCode", user.UserTypeCode));
            list.Add(new SqlParameter("StatusCode", user.StatusCode));
            list.Add(new SqlParameter("CreatedBy", user.CreatedById));
            this._SQLHelper.ExecuteNonQuery(strStoredProcedure, list, CommandType.StoredProcedure);
        }

        public void Update(InternalUser user)
        {
            string strStoredProcedure = "MsInternalUserUpdate";
            List<SqlParameter> list = new List<SqlParameter>();
            list.Add(new SqlParameter("UserId", user.UserId));
            list.Add(new SqlParameter("UserName", user.UserName));
            list.Add(new SqlParameter("UserTypeCode", user.UserTypeCode));
            list.Add(new SqlParameter("StatusCode", user.StatusCode));
            list.Add(new SqlParameter("UpdatedBy", user.UpdatedById));
            this._SQLHelper.ExecuteNonQuery(strStoredProcedure, list, CommandType.StoredProcedure);
        }

        public DataSet GetInternalUserByUserName(string strUserName)
        {
            string strStoredProcedure = "MsInternalUserSelectByUserName";
            List<SqlParameter> list = new List<SqlParameter>();
            list.Add(new SqlParameter("UserName", strUserName));
            DataSet ds = this._SQLHelper.GetDataSet(strStoredProcedure, list, CommandType.StoredProcedure);

            return ds;
        }

        public DataSet GetInternalUserById(int userId)
        {
            string strStoredProcedure = "MsInternalUserSelectById";
            List<SqlParameter> list = new List<SqlParameter>();
            list.Add(new SqlParameter("UserId", userId));
            DataSet ds = this._SQLHelper.GetDataSet(strStoredProcedure, list, CommandType.StoredProcedure);

            return ds;
        }

        public static InternalUserDAL GetInstance()
        {
            if (_InternalUserDAL == null)
                _InternalUserDAL = new InternalUserDAL();

            return _InternalUserDAL;
        }

        #endregion
    }
}